package code.lewdy.app.communication;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import code.lewdy.db.HibernateTemple;
import code.lewdy.util.FormatUtil;

import com.lt.member.Member;

/**即时通知、消息,可用于即时弹窗通知
 * 1.充值100元已成功，请核对,订单号XXXX
 * 2.您提现100元正在等候处理，请稍后,订单号XXXX
 * 3. 站内信
 * 4.盈亏
 * @author Administrator
 *
 */
@Entity
@Table
public class Alert {
	private long id;
	private long ownerId;
	private String ownerName;
	private String title;
	private String content;
	private int isAlert; //是否提示过 0-未|1-已提示
	private int typeId; //消息类型
	private Date createDate;
	
	public Long save(Member m, String title, String content){
		if(m == null){
			m = new Member();
			m.setId(0);  // 会员id为0一般指全体会员不指单个
			m.setUsername("全体会员");
		}
		this.ownerId = new Long(m.getId());
		this.ownerName = m.getUsername();
		this.title = title;
		this.content = content;
		this.isAlert = 0;
		this.createDate = new Date();
		Long alertId = HibernateTemple.save(this);
		return alertId;
	}
	
	@Id
	@GeneratedValue
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	public long getOwnerId() {
		return ownerId;
	}
	public void setOwnerId(long ownerId) {
		this.ownerId = ownerId;
	}
	@Column(length=30)
	public String getOwnerName() {
		return ownerName;
	}
	public void setOwnerName(String ownerName) {
		this.ownerName = ownerName;
	}
	@Column(length=30)
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public int getIsAlert() {
		return isAlert;
	}
	public void setIsAlert(int isAlert) {
		this.isAlert = isAlert;
	}
	public int getTypeId() {
		return typeId;
	}
	public void setTypeId(int typeId) {
		this.typeId = typeId;
	}
	@Temporal(TemporalType.TIMESTAMP)
	public Date getCreateDate() {
		return createDate;
	}
	@Transient
	public String getDate(){
		return FormatUtil.formatDate(createDate, "yyyy-MM-dd HH:mm:ss");
	}
	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}
	
	
}
